# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/4 下午3:53
 @Author  : tgy


 对象的属性查找顺序:
 数据描述符 -> 对象属性 -> 非数据描述-> 类属性 -> 父类属性

"""
from weakref import WeakKeyDictionary


class descriptor:
    ...

    def __init__(self, label):
        self.label = label

    def __get__(self, instance, owner):
        return instance.__dict__[self.label]

    def __set__(self, instance, value):
        instance.__dict__[self.label] = value


class descriptor:
    ...

    def __init__(self, default=None):
        self.default = default
        self.container = WeakKeyDictionary()

    def __get__(self, instance, owner):
        return self.container.get(instance, self.default)

    def __set__(self, instance, value):
        self.container[instance] = value


class Person:
    name = descriptor('name')

    def __init__(self, name):
        self.name = name


if __name__ == '__main__':
    ...
    per = Person('zhangsan')
    print(per.name)
